<template>
<div class="visualBlock">
    <div class="title-header">
      <div class="left-menu" @click="$router.push({path: '/'})"><i class="iconfont icon-left"></i></div>
      <div class="title center">疫情摸底排查现场登记</div>
      <div class="extras" @click="addNew()">新增</div>
    </div>
    <div class="scrollList">
      <ul v-infinite-scroll="getList" infinite-scroll-disabled="busy" infinite-scroll-distance="20">
        <li v-for="(item, index) in list" :key="index" @click="itemClick(item)">
          <div class="list_content">
            <div class="list_title"><span>{{item.area}}</span>{{item.xm}}</div>
            <p>时间：{{item.date}}</p>
          </div>
          <div class="clear"></div>
        </li>
      </ul>
    </div>
    <router-view @refresh="refresh"></router-view>
</div>
</template>

<script>
import MulImage from '@/components/component/MyMulImage';
import { XButton, Popup, PopupPicker } from 'vux';
export default {
  name: "List",
  components: {
    XButton, Popup, PopupPicker, MulImage
  },
  data () {
    return {
      total: 0,
      list: [],
      busy: true,
      allLoad: false
    };
  },
  methods: {
    addNew: function () {
      this.$router.push({path: '/list3/add'});
    },
    itemClick: function (item) {
      this.$router.push({path: '/list3/view', query: {id: item.id}});
    },
    refresh: function () {
      this.getList(1);
    },
    getList: function (pageNo) {
      var vm = this;
      if (pageNo) {
        vm.pageNo = pageNo;
        vm.pageNo == 1 && (vm.list = []);
      } else {
        vm.pageNo++;
      }
      vm.busy = true;
      var params = {
        pageNo: vm.pageNo
      };
      vm.$getAndLoad('列表', 'oa/ycdc/list.jsp?' + vm.$util.stringify(params), function (data) {
        data.result.forEach(element => {
          vm.list.push(element);
        });
        vm.total = data.total;
        if (data.result.length < 20) {
          vm.allLoad = true;
          vm.$vux.toast.text('已显示全部', 'bottom');
          return;
        }
        vm.busy = false;
      });
    }
  },
  mounted: function () {
    this.getList(1);
  }
};
</script>

<style lang="scss" scoped>
.visualBlock {
  background: #fff;
}
.scrollList {
  position: fixed;
  top: 40px;
  width: 100%;
  height: calc(100vh - 40px);
}
.scrollList {
  height: calc(100vh - 40px);
  overflow-y: scroll;
  -webkit-overflow-touch: touch;
  background: #fbf5f5;
  ul {
    li {
      background: #fff;
      margin-bottom: 3px;
      padding: 10px;
      .list_title {
        font-size: 15px;
        display: flex;
        justify-content: space-between;
        span {
          font-weight: bold;
        }
      }
    }
  }
}
</style>
